package com.device.operating.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.device.operating.dao.DproleRepository;
import com.device.operating.entity.Dprole;
import com.device.operating.service.DproleService;

@Service("DproleService")
@Transactional(propagation=Propagation.REQUIRED)
public class DproleServiceImpl implements DproleService{
	
	@Autowired
	private DproleRepository DproleRepository;

	@Override
	public void adddprole(Dprole dprole) {
		// TODO Auto-generated method stub
		DproleRepository.save(dprole);
	}

	@Override
	public void deletedprole(Dprole dprole) {
		// TODO Auto-generated method stub
		DproleRepository.delete(dprole);
	}

	@Override
	public List<Dprole> querybydpId(String departmentId) {
		// TODO Auto-generated method stub
		return DproleRepository.findByDepartmentId(departmentId);
	}

	@Override
	public void updatedproles(String dpId, List<Dprole> list) {
		// TODO Auto-generated method stub
		if(list.size()==0){
			return;
		}
		List<Dprole> listdprole=DproleRepository.findByDepartmentId(dpId);
		for(Dprole dprole:listdprole){
			DproleRepository.delete(dprole.getDproleId());
		}
		DproleRepository.save(list);
	}
	

	
}
